package com.gtenacg.cartoonservice.controller;

import com.gtenacg.cartoonservice.common.annotation.CheckToken;
import com.gtenacg.cartoonservice.common.Result;
import com.gtenacg.cartoonservice.pojo.model.RelationNovelAuthor;
import com.gtenacg.cartoonservice.service.RelationNovelAuthorService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/relationNovelAuthor")
@CheckToken
public class RelationNovelAuthorController {

    final RelationNovelAuthorService relationNovelAuthorService;

    @GetMapping
    public Result<List<RelationNovelAuthor>> search(
            @RequestParam(required = false) Integer nid,
            @RequestParam(required = false) Integer aid
    ) {
        log.info("获取对应列表（电子书-作者）, nid:{},aid:{}", nid, aid);
        List<RelationNovelAuthor> list = relationNovelAuthorService.search(nid, aid);
        return Result.success(list);
    }

    @GetMapping("/list")
    public Result<List<RelationNovelAuthor>> list() {
        log.info("获取对应列表（电子书-作者）");
        List<RelationNovelAuthor> list = relationNovelAuthorService.list();
        return Result.success(list);
    }

    @PostMapping
    public Result<Integer> insert(@RequestBody RelationNovelAuthor relationNovelAuthor) {
        log.info("新增对应关系（电子书-作者）: {}", relationNovelAuthor);
        Integer id = relationNovelAuthorService.insert(relationNovelAuthor);
        return Result.success(id);
    }

    @PutMapping
    public Result<Void> update(@RequestBody RelationNovelAuthor relationNovelAuthor) {
        log.info("更新对应关系（电子书-作者）: {}", relationNovelAuthor);
        relationNovelAuthorService.update(relationNovelAuthor);
        return Result.success();
    }

    @DeleteMapping("/{ids}")
    public Result<Void> delete(@PathVariable List<Integer> ids) {
        log.info("删除对应关系（电子书-作者）: {}", ids);
        relationNovelAuthorService.delete(ids);
        return Result.success();
    }

}
